home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jdoc / jedit_prog.jdoc < prev    next >
Encoding:
Text File  |  1995-02-10  |  13.5 KB  |  1 lines

  1. Programming\ with\ jedit\n\nIntroduction\nThis\ document\ describes\ aspects\ of\ jedit\ relevant\ to\ Tk/Tcl\ programmers\ and\ advanced\ jedit\ users,\ including\ how\ to\ write\ new\ editing\ modes\ (or\ modify\ existing\ ones)\ and\ how\ to\ incorporate\ jedit\ windows\ in\ your\ own\ applications.\n\nWriting\ Editing\ Modes\n(This\ section\ isn't\ quite\ finished,\ but\ it\ should\ have\ enough\ to\ get\ you\ started,\ if\ you\ also\ look\ at\ the\ code\ for\ existing\ editing\ modes,\ especially\ hook-mode,\ which\ is\ a\ demonstration\ of\ the\ various\ facilities\ available.)\n\nYou\ create\ a\ new\ editing\ mode\ by\ creating\ a\ file\ called\ mode-mode.tcl,\ where\ mode\ is\ the\ name\ of\ the\ new\ mode.\ \ This\ file\ can\ live\ in\ any\ of\ the\ directories\ ~/.tk/jeditmodes,\ \$tk_library/jedit/jeditmodes,\ or\ \$tk_library/jeditmodes.\ \ (The\ directories\ are\ searched\ in\ that\ order.)\n\nThe\ bare\ minimum\ a\ new\ mode\ file\ should\ have\ in\ it\ is\ a\ procedure\ mode:mode:init\ (where\ mode\ is\ the\ name\ of\ the\ mode)\ which\ contains\ code\ like\ the\ following,\ to\ set\ mode¡specific\ preferences:\n\n\tproc\ mode:mail:init\ {\ t\ }\ {\n\t\ \ global\ MODEPREFS\n\t\ \ \n\t\ \ j:read_prefs\ -array\ MODEPREFS\ -prefix\ mail\ \\\n\t\ \ \ \ -directory\ ~/.tk/jeditmodes\ -file\ mail-defaults\ {\n\t\ \ \ \ {textfont\ default}\n\t\ \ \ \ {textwidth\ 80}\n\t\ \ \ \ {textheight\ 24}\n\t\ \ \ \ {textwrap\ char}\n\t\ \ \ \ {sabbrev\ 0}\n\t\ \ \ \ {dabbrev\ 0}\n\t\ \ \ \ {autobreak\ 1}\n\t\ \ \ \ {autoindent\ 0}\n\t\ \ \ \ {savestate\ 0}\n\t\ \ \ \ {buttonbar\ 1}\n\t\ \ \ \ {menu,editor\ 1}\n\t\ \ \ \ {menu,file\ 1}\n\t\ \ \ \ {menu,edit\ 1}\n\t\ \ \ \ {menu,prefs\ 0}\n\t\ \ \ \ {menu,abbrev\ 1}\n\t\ \ \ \ {menu,filter\ 1}\n\t\ \ \ \ {menu,format\ 0}\n\t\ \ \ \ {menu,display\ 0}\n\t\ \ \ \ {menu,mode1\ 1}\n\t\ \ \ \ {menu,mode2\ 1}\n\t\ \ \ \ {menu,user\ 1}\n\t\ \ }\n\t}\n\n(Actually,\ you\ can\ leave\ out\ the\ preferences\ you\ don't\ want\ to\ override\ in\ your\ mode\ in\ the\ list\ you\ give\ to\ j:read_prefs.)\ \ This\ code\ fragment\ sets\ the\ defaults\ for\ the\ various\ mode¡specific\ preferences\ for\ your\ new\ mode,\ although\ a\ user\ can\ still\ override\ them\ (for\ this\ particular\ mode)\ on\ the\ Mode¡Specific\ Preferences\ panel.\n\nNote\ that\ the\ mode:mode:init\ procedure\ gets\ an\ argument\ t.\ \ That's\ the\ name\ of\ the\ text\ widget\ whose\ mode\ is\ being\ set,\ so\ you\ can\ do\ things\ like\ configure\ tags\ or\ add\ bindings\ if\ you\ need\ to.\n\nIf\ you\ need\ to\ refer\ to\ the\ widget's\ toplevel\ (for\ instance,\ to\ add\ new\ user¡interface\ components),\ you\ can\ do\ that\ with\ the\ command\ `jedit:text_to_top\ \$t'.\ \ If\ you\ do\ anything\ in\ mode:mode:init\ that\ shouldn't\ persist\ if\ the\ user\ changes\ modes,\ you\ should\ also\ provide\ a\ procedure\ called\ mode:mode:cleanup\ (which\ will\ also\ be\ called\ with\ the\ text\ widget\ as\ its\ sole\ argument)\ to\ undo\ your\ changes.\ \ For\ instance,\ if\ you\ pack\ an\ entry\ for\ the\ user\ to\ type\ a\ cryptographic\ key\ into\ the\ toplevel\ window\ in\ mode:crypt:init,\ you\ should\ create\ a\ mode:crypt:cleanup\ procedure\ to\ remove\ it.\ \ (Both\ procedures\ would\ need\ to\ use\ jedit:text_to_top\ to\ get\ the\ name\ of\ the\ toplevel\ window.)\n\nIf\ you\ want\ to\ create\ a\ custom\ buttonbar,\ you\ can\ define\ a\ procedure\ called\ mode:mode:mkbuttons\ with\ code\ similar\ to\ the\ following:\n\n\tproc\ mode:mail:mkbuttons\ {\ w\ t\ }\ {\n\t\ \ j:buttonbar\ \$w\ -pady\ 2\ -buttons\ \[format\ {\n\t\ \ \ \ {done\ Done\ {jedit:cmd:done\ %s}}\n\t\ \ \ \ {sign\ Sign\ {mode:mail:insert_sig\ %s}}\n\t\ \ }\ \$t\ \$t\]\n\t\ \ return\ \$w\n\t}\n\nThis\ procedure\ gets\ both\ the\ name\ of\ the\ toplevel\ widget\ and\ the\ name\ of\ the\ text\ widget.\ \ It\ should\ create\ the\ buttonbar\ as\ a\ child\ of\ the\ toplevel\ and\ return\ its\ path,\ but\ not\ pack\ it\ itself.\n\nYou\ can\ further\ customise\ the\ behaviour\ of\ the\ editor\ in\ your\ new\ mode\ by\ creating\ any\ of\ the\ following\ procedures:\n\n\tmode:mode:pre_read_hook\ filename\ widget\n\tmode:mode:read\ filename\ widget\ \n\tmode:mode:post_read_hook\ filename\ widget\n\t\n\tmode:mode:pre_write_hook\ filename\ widget\n\tmode:mode:write\ filename\ widget\n\tmode:mode:post_write_hook\ filename\ widget\n\t\t\n\tmode:mode:pre_quit_hook\ widget\n\tmode:mode:quit\ widget\n\t\n\tmode:mode:pre_close_hook\ widget\n\tmode:mode:close\ widget\n\t\n\tmode:mode:pre_spacebar_hook\ widget\n\tmode:mode:spacebar\ widget\n\tmode:mode:post_spacebar_hook\ widget\n\t\n\tmode:mode:pre_tabkey_hook\ widget\n\tmode:mode:tabkey\ widget\n\tmode:mode:post_tabkey_hook\ widget\n\t\n\tmode:mode:pre_returnkey_hook\ widget\n\tmode:mode:returnkey\ widget\n\tmode:mode:post_returnkey_hook\ widget\n\t\n\tmode:mode:pre_paste_hook\ widget\n\tmode:mode:post_paste_hook\ widget\n\t\n\tmode:mode:pre_xpaste_hook\ widget\n\tmode:mode:post_xpaste_hook\ widget\n\t\n\tmode:mode:autoindent\ widget\n\nIf\ a\ mode:mode:pre_..._hook\ or\ mode:mode:post_..._hook\ procedure\ is\ defined,\ it\ will\ be\ called\ before\ or\ after\ the\ relevant\ action.\ \ If\ one\ of\ the\ procedures\ without\ `_hook'\ is\ defined,\ it\ will\ be\ called\ instead\ of\ the\ default\ action.\n\nNote\ that\ the\ behaviour\ of\ the\ `Close'\ command\ and\ it's\ corresponding\ mode¡specific\ procedures\ is\ linked\ to\ that\ of\ the\ `Quit'\ command\ and\ it's\ corresponding\ mode¡specific\ procedures.\ \ If\ there\ is\ only\ one\ window\ open,\ choosing\ `Close'\ is\ exactly\ like\ choosing\ `Quit',\ and\ will\ trigger\ mode:mode:pre_quit_hook\ and\ mode:mode:quit\ if\ they\ exist\ rather\ than\ the\ corresponding\ `Close'\ hooks.\ \ The\ mode:mode:pre_close_hook\ and\ mode:mode:close\ procedures\ are\ called\ only\ when\ there's\ more\ than\ one\ window\ open.\ \ This\ means\ that\ if\ you\ define\ them,\ you\ usually\ want\ to\ take\ similar\ actions\ in\ the\ corresponding\ `Quit'\ hooks.\n\nMode¡Specific\ Menus\nIf\ you\ want\ to\ create\ a\ special\ menu\ for\ your\ jedit\ mode,\ you\ can\ create\ a\ procedure\ called\ mode:mode:mkmenu1,\ where\ mode\ is\ the\ name\ of\ your\ mode.\ \ It\ will\ receive\ two\ arguments:\ the\ name\ of\ a\ menubutton\ to\ create,\ and\ the\ name\ of\ the\ jedit\ text\ widget\ this\ menu\ is\ attached\ to.\ \ As\ an\ example,\ here's\ the\ procedure\ that\ define's\ the\ mail\ mode's\ `Mail'\ menu:\n\n\t##################################################\n\t#\ define\ the\ Mail\ menu:\n\t##################################################\n\t\n\tproc\ mode:mail:mkmenu1\ {\ menu\ t\ }\ {\n\t\ \ menubutton\ \$menu\ -text\ {Mail}\ -menu\ \$menu.m\n\t\ \ \n\t\ \ menu\ \$menu.m\n\t\ \ \$menu.m\ add\ command\ -label\ {Sign\ Email}\ -command\ \"\n\t\ \ \ \ mode:mail:insert_sig\ \$t\n\t\ \ \"\n\t\ \ \$menu.m\ add\ command\ -label\ {Done}\ -command\ \"\n\t\ \ \ \ jedit:cmd:done\ \$t\n\t\ \ \"\n\t}\n\n(In\ this\ example,\ mode:mail:insert_sig\ is\ a\ procedure\ defined\ elsewhere\ in\ the\ mail-mode.tcl\ file.)\n\nNote\ that\ the\ mode:mode:mkmenu1\ procedure\ has\ to\ create\ the\ menubutton\ itself\ (but\ not\ pack\ it),\ and\ it\ has\ no\ control\ over\ the\ name\ of\ the\ menubutton\ widget.\n\nIf\ you\ want\ to\ create\ two\ mode¡specific\ menus,\ you\ can\ also\ define\ a\ mode:mode:mkmenu2\ procedure\;\ the\ requirements\ are\ the\ same\ as\ for\ mode:mode:mkmenu1.\n\nEmbedding\ jedit\ in\ Other\ Applications\nAlmost\ all\ the\ functionality\ of\ jedit\ is\ in\ libraries,\ so\ if\ you\ write\ your\ own\ Tk¡based\ applications,\ you\ can\ easily\ incorporate\ jedit\ into\ them.\ \ You\ need\ to\ include\ a\ little\ bit\ of\ code\ at\ the\ beginning\ of\ your\ application\ to\ allow\ it\ to\ use\ the\ jstools\ libraries\;\ this\ is\ described\ in\ the\ Usage\ section\ of\ their\ documentation.\ \ Essentially,\ you\ need\ to\ make\ sure\ the\ auto_path\ Tcl\ variable\ is\ set\ properly\ to\ find\ the\ libraries.\ \ Then\ you\ can\ say\n\tjedit:jedit\ \[-window\ w\]\ \[-mode\ mode\]\ \[-file\ filename\]\nto\ edit\ a\ file\ (or\ open\ a\ new\ empty\ document\ window,\ if\ you\ don't\ specify\ `-file\ filename').\n\nIf\ the\ window\ w\ doesn't\ already\ exist,\ it\ will\ be\ created\ as\ a\ new\ toplevel\ window.\ \ (If\ you\ don't\ specify\ it,\ an\ arbitrary\ window\ name\ will\ be\ chosen.)\ \ It's\ fine\ for\ w\ to\ exist\ already,\ though\;\ that\ way\ you\ can\ include\ an\ entire\ jedit\ window\ inside\ another\ window.\n\nIf\ you\ specify\ mode,\ the\ window\ will\ be\ in\ that\ mode\;\ otherwise\ jedit\ will\ guess\ the\ mode\ based\ on\ the\ filename.\n\nIf\ you\ specify\ mode\ and\ also\ define\ all\ the\ necessary\ procedures\ for\ that\ mode\ in\ your\ code\ before\ calling\ jedit:jedit\ (such\ as\ mode:mode:init),\ you\ can\ tightly\ constrain\ the\ behaviour\ of\ the\ resulting\ jedit\ window,\ essentially\ creating\ a\ custom\ mode\ for\ your\ application\ without\ having\ to\ provide\ a\ separate\ mode\ file\ to\ define\ it.\n\n {{{sel {123.152 124.0}} {jdoc:xref:link {4.35 4.40 4.125 4.138 7.150 7.159 42.297 42.322 126.245 126.266 126.289 126.306}} {jdoc:anchor:anchorname {3.0 4.0 6.0 7.0 100.0 101.0 125.0 126.0}} {richtext:font:roman {2.0 3.0 4.0 4.35 4.40 4.85 4.90 4.188 4.193 6.0 7.0 7.150 7.159 9.56 9.69 9.157 9.173 9.175 9.203 9.208 9.230 11.66 11.80 11.88 11.92 11.190 11.191 13.0 41.0 42.109 42.121 44.14 44.28 44.56 44.57 46.134 46.154 46.180 46.194 46.288 46.305 46.503 46.518 46.540 46.558 46.619 46.636 48.76 48.95 50.0 57.0 62.0 95.0 96.5 96.19 96.22 96.27 96.31 96.46 96.49 96.54 96.167 96.172 96.204 96.214 98.239 98.246 98.286 98.309 98.314 98.328 98.393 98.417 98.422 98.437 98.460 98.464 100.0 101.0 101.46 101.51 101.92 101.109 101.117 101.121 101.236 101.241 101.335 101.339 103.0 118.0 119.18 119.38 119.79 119.92 121.14 121.31 123.69 123.86 123.135 123.152 125.0 126.0 126.32 126.37 126.130 126.135 126.249 126.256 126.293 126.298 126.371 126.380 127.0 127.13 127.14 127.23 127.24 127.25 127.26 127.36 127.37 127.38 127.39 127.53 128.75 128.89 130.14 130.15 130.168 130.169 130.231 130.236 132.15 132.19 132.64 132.69 134.15 134.19 134.107 134.118 134.128 134.142 134.202 134.207 136.0}} {richtext:font:italic {9.56 9.60 11.71 11.75 11.88 11.92 44.19 44.23 44.56 44.57 46.185 46.189 46.293 46.297 48.81 48.85 62.6 62.10 62.25 62.33 62.34 62.40 63.6 63.10 63.16 63.24 63.25 63.31 64.6 64.10 64.26 64.34 64.35 64.41 66.6 66.10 66.26 66.34 66.35 66.41 67.6 67.10 67.17 67.25 67.26 67.32 68.6 68.10 68.27 68.35 68.36 68.42 70.6 70.10 70.25 70.31 71.6 71.10 71.16 71.22 73.6 73.10 73.26 73.32 74.6 74.10 74.17 74.23 76.6 76.10 76.29 76.35 77.6 77.10 77.20 77.26 78.6 78.10 78.30 78.36 80.6 80.10 80.27 80.33 81.6 81.10 81.18 81.24 82.6 82.10 82.28 82.34 84.6 84.10 84.30 84.36 85.6 85.10 85.21 85.27 86.6 86.10 86.31 86.37 88.6 88.10 88.26 88.32 89.6 89.10 89.27 89.33 91.6 91.10 91.27 91.33 92.6 92.10 92.28 92.34 94.6 94.10 94.22 94.28 96.10 96.14 96.36 96.40 96.204 96.214 98.239 98.246 98.291 98.295 98.319 98.323 98.398 98.402 98.427 98.431 98.460 98.464 101.97 101.101 101.117 101.121 119.23 119.27 121.19 121.23 123.74 123.78 123.140 123.144 127.22 127.23 127.32 127.36 127.45 127.53 128.81 128.89 130.14 130.15 130.168 130.169 132.15 132.19 134.15 134.19 134.133 134.137}} {richtext:font:bold {9.60 9.69 9.157 9.173 9.186 9.203 9.219 9.230 119.79 119.92 126.249 126.256}} {richtext:font:bolditalic {126.293 126.298}} {richtext:font:typewriter {4.35 4.40 4.85 4.90 4.188 4.193 7.150 7.159 9.175 9.186 9.208 9.219 11.66 11.71 11.75 11.80 11.190 11.191 13.0 41.0 42.109 42.121 44.14 44.19 44.23 44.28 46.134 46.154 46.180 46.185 46.189 46.194 46.288 46.293 46.297 46.305 46.503 46.518 46.540 46.558 46.619 46.636 48.76 48.81 48.85 48.95 50.0 57.0 62.0 62.6 62.10 62.25 62.33 62.34 62.40 63.6 63.10 63.16 63.24 63.25 63.31 64.6 64.10 64.26 64.34 64.35 64.41 66.6 66.10 66.26 66.34 66.35 66.41 67.6 67.10 67.17 67.25 67.26 67.32 68.6 68.10 68.27 68.35 68.36 68.42 70.6 70.10 70.25 70.31 71.6 71.10 71.16 71.22 73.6 73.10 73.26 73.32 74.6 74.10 74.17 74.23 76.6 76.10 76.29 76.35 77.6 77.10 77.20 77.26 78.6 78.10 78.30 78.36 80.6 80.10 80.27 80.33 81.6 81.10 81.18 81.24 82.6 82.10 82.28 82.34 84.6 84.10 84.30 84.36 85.6 85.10 85.21 85.27 86.6 86.10 86.31 86.37 88.6 88.10 88.26 88.32 89.6 89.10 89.27 89.33 91.6 91.10 91.27 91.33 92.6 92.10 92.28 92.34 94.6 94.10 94.22 94.28 95.0 96.5 96.10 96.14 96.19 96.22 96.27 96.31 96.36 96.40 96.46 96.49 96.54 96.167 96.172 98.286 98.291 98.295 98.309 98.314 98.319 98.323 98.328 98.393 98.398 98.402 98.417 98.422 98.427 98.431 98.437 101.46 101.51 101.92 101.97 101.101 101.109 101.236 101.241 101.335 101.339 103.0 118.0 119.18 119.23 119.27 119.38 121.14 121.19 121.23 121.31 123.69 123.74 123.78 123.86 123.135 123.140 123.144 123.152 126.32 126.37 126.130 126.135 126.371 126.380 127.0 127.13 127.14 127.22 127.24 127.25 127.26 127.32 127.37 127.38 127.39 127.45 128.75 128.81 130.231 130.236 132.64 132.69 134.107 134.118 134.128 134.133 134.137 134.142 134.202 134.207}} {richtext:font:heading0 {1.0 2.0}} {richtext:font:heading1 {3.0 4.0 6.0 7.0 100.0 101.0 125.0 126.0}} {jdoc:anchorname:Writing_Editing_Modes {6.0 7.0}} {jdoc:link:jeditmodes/hook-mode.jdoc {7.150 7.159}} {{} {124.0 135.0}} {jdoc:anchorname:Embedding_jedit_in_Other_Applications {125.0 126.0}} {jdoc:link:jslibraries.jdoc {126.245 126.266}} {jdoc:link:jslibraries.jdoc#Usage {126.289 126.306}} {jdoc:link:jedit.jdoc {4.35 4.40}} {jdoc:link:jedit.jdoc#Editing_Modes {4.125 4.138}} {jdoc:anchorname:Introduction {3.0 4.0}} {jdoc:link:jedit.jdoc#Mode¡Specific_Preferences {42.297 42.322}} {jdoc:anchorname:Mode¡Specific_Menus {100.0 101.0}}} {{matchend 98.182} {abbrevstart 124.0} {abbrevend 124.0} {insert 123.152} {matchstart 98.172} {anchor 123.152} {current 4.118}}}